package easymall.controller.admin;

import java.io.OutputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import easymall.po.Order;
import easymall.service.OrderService;
import easymall.service.OrdersExportService;
@Controller("ordersExportController")
public class OrdersExportController {
	@Autowired  
    private OrdersExportService ordersExportService;  
	@Autowired
	private OrderService orderService;
  
	@RequestMapping(value = "admin/excel/export")   
    public void exportExcel(HttpServletRequest request, HttpServletResponse response)   
    throws Exception {  
          
        List<Order> list = orderService.findAllOrders();
        HSSFWorkbook wb = ordersExportService.export(list);  
        response.setContentType("application/vnd.ms-excel");  
        response.setHeader("Content-disposition", "attachment;filename=Orders.xls");  
        OutputStream ouputStream = response.getOutputStream();  
        wb.write(ouputStream);  
        ouputStream.flush();  
        ouputStream.close();  
   }  
}
